package com.work.xxzl.module.pagehome;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.work.xxzl.R;
import com.work.xxzl.adapter.CommonRecyclerViewAdapter;
import com.work.xxzl.adapter.CommonRecyclerViewHolder;
import com.work.xxzl.base.BaseFragment;
import com.work.xxzl.utils.UIUtils;
import com.work.xxzl.view.DividerItemDecoration;
import com.work.xxzl.view.SwipRefreshViewCommon;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * author: Aly
 * date :2018/12/7 16:27
 * version:1.0
 * description:恋爱墙
 */
public class LoveWallFragment extends BaseFragment {
    @BindView(R.id.recycleview)
    RecyclerView recycleview;
    @BindView(R.id.swiprefreshview)
    SwipRefreshViewCommon swiprefreshview;
    private List<String> mDatas = new ArrayList<>();
    private CommonRecyclerViewAdapter<String> adapter;

    @Override
    protected int getLayoutId() {
        return R.layout.layout_recycleview;
    }

    @Override
    protected void initView() {
        setAdapter();
    }


    @Override
    protected void initData() {
        super.initData();
        setRefresh();
    }

    private void setRefresh() {
        swiprefreshview.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swiprefreshview.setRefreshing(false);
            }
        });
    }

    //设置适配器
    private void setAdapter() {
        for (int i = 0; i < 10; i++) {
            mDatas.add("");
        }
        adapter = new CommonRecyclerViewAdapter<String>(getContext(), mDatas) {

            @Override
            public void convert(CommonRecyclerViewHolder holder, String entity, int position) {

            }

            @Override
            public int getLayoutViewId(int viewType) {
                return R.layout.item_homepage_lovewall;
            }
        };
        recycleview.setPadding(0, 0, 0, 0);
        recycleview.setBackgroundColor(getResources().getColor(R.color.bg_grayf5));
        recycleview.setLayoutManager(new LinearLayoutManager(getContext()));
        recycleview.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL, UIUtils.dip2px(10), R.color.bg_grayf5));
        recycleview.setAdapter(adapter);
    }
}
